#include("../common/header.html")
<script type="text/javascript">
	//调用微信JS api 支付

	$(document)[0].title="会员升级";
	function callpay(obj)
	{
		var paytype = 2;
		var level = $(obj).attr('level');
		var curlevel = '#(vipId)';
		
      var ua = window.navigator.userAgent.toLowerCase();
		if(paytype==1 && ua.match(/MicroMessenger/i) == 'micromessenger'){
			if (typeof WeixinJSBridge == "undefined"){
			    if( document.addEventListener ){
			        document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
			    }else if (document.attachEvent){
			        document.attachEvent('WeixinJSBridgeReady', jsApiCall); 
			        document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
			    }
			}else{
				$.ajax({
					type: "GET",
					url: "#(ctx)/wap/recommend/rule/upgrade",
					data: {level:level},
					dataType: "json",
					success: function(data){
						var jsApiParameters = data;
						WeixinJSBridge.invoke(
							'getBrandWCPayRequest',
							jsApiParameters,
							function(res){
								WeixinJSBridge.log(res.err_msg);
								window.location.reload();
							}
						);
					}
				});
			}
		}else if(paytype==1 && ua.match(/MicroMessenger/i) != 'micromessenger'){
			/*
			$.ajax({
				type: "GET",
				url: "#(ctx)/wap/recommend/rule/upgrade",
				data: {ruleId:level},
				dataType: "json",
				success: function(data){
					location.href=data.mweb_url
				}
			});
			*/
			location.href= '#(ctx)/wap/recharge/order/payment?ruleId='+level;
		}else{
			/*
			$.ajax({
				type: "GET",
				url: "#(ctx)/wap/recharge/order",
				data: {ruleId:level},
				dataType: "json",
				success: function(data){
					console.log(data);
					if(data.code==200){
						//window.location.href=data.url;
					}

				}
			});
			*/
			if(curlevel !=='') {
				if(confirm("您已经是代理,如果购买成功会覆盖已有权益确认再次购买吗?")){
					location.href= '#(ctx)/wap/recharge/order/payment?ruleId='+level;
				}
			}else{
					location.href= '#(ctx)/wap/recharge/order/payment?ruleId='+level;
			}
		}
	}
</script>
<body>
	<div id="container" style="background-color:#F5F5F5">
		<div class="topItems flex">
			<div class="middle selVip" style="" id="class1">#(mediumName)</div>
			<div class="middle" id="class2">#(seniorName)</div>
		</div>
		<div class="member flex" style="background:url(#(ctxWapSt)/h5css/images/Vbg.png) no-repeat;background-size:100% 100%;">
			<div class="memberVip">
				<div class='memberTop'><text class="class1">#(mediumRecommendRule.recName)</text>规则</div>
				<div class="memberMain column">
					<div class="level1">
						#if(mediumRecommendRule.recVal1 > 0)
						<div>·享受一级代理佣金收益【#(mediumRecommendRule.recVal1)%】提成</div>
						#end
						#if(mediumRecommendRule.recVal2 > 0)
						<div>·享受二级代理佣金收益【#(mediumRecommendRule.recVal2)%】提成</div>
						#end
						#if(mediumRecommendRule.recVal3 > 0)
						<div>·享受三级代理佣金收益【#(mediumRecommendRule.recVal2)%】提成</div>
						#end
					</div>
					<div class="level2">
						#if(seniorRecommendRule.recVal1 > 0)
						<div>·享受一级代理佣金收益【#(seniorRecommendRule.recVal1)%】提成</div>
						#end
						#if(seniorRecommendRule.recVal2 > 0)
						<div>·享受二级代理佣金收益【#(seniorRecommendRule.recVal2)%】提成</div>
						#end
						#if(seniorRecommendRule.recVal3 > 0)
						<div>·享受三级代理佣金收益【#(seniorRecommendRule.recVal2)%】提成</div>
						#end
					</div>
					<div style="color:#333333" class="flex"><text>晋升【</text><text class="class1">#(mediumName)</text><text>】后将享有以上的高级权益</text></div>
				</div>
			</div>
		</div>
		<div class="membertitle">升级费用</div>
		<div class="vipMoney column" style="background:url(#(ctxWapSt)/h5css/images/middle.png) no-repeat;background-size:100% 100%;" >
			<div class="vipName class1">#(seniorName)</div>
			<div class="vipPrice">￥#(mediumRecommendRule.recAmount)元</div>
			<div class="vipLine"></div>
		</div>
		<div class="membertitle">支付方式</div>
		<div class="wechatpay flex">
			<img src="#(ctxWapSt)/h5css/images/wechat.png" alt="">	
			<div>微信支付</div>	
		</div>

		<div class="pay gopay" onclick="callpay(this)" level="#(mediumRecommendRule.id)">确认支付</div>
		<div class="pay nopay">您已经是#(vipName)</div>
		<!-- 
		<p style="text-align:center;margin: 13px;font-size: 14px;color: #7c7c7c;">扫码支付后请等待页面自动刷新完成</p>
		 -->
	</div>
</body>
<script>
	$(document).ready(function (){
        var nScrollHight = 0; //滚动距离总长(注意不是滚动条的长度)
        var nScrollTop = 0;   //滚动到的当前位置
        var nDivHight = $("#container").height();
        $("#container").scroll(function(){
        	nScrollHight = $(this)[0].scrollHeight;
        	nScrollTop = $(this)[0].scrollTop;
        	if(nScrollTop + nDivHight >= nScrollHight){
        		// alert("滚动条到底部了");
        		console.log("到底了");
        	}
        });

        $(".level1").show();
        $(".level2").hide();
        var curlevel = '#(vipId)';
        if(curlevel=='#(mediumRecommendRule.id)'){
        	$(".gopay").hide();
        	$(".nopay").show();
        }else{
        	$(".nopay").hide();
        	$(".gopay").show();
        }
        $(".topItems>.middle").on("click",function(){
        	$(this).addClass("selVip").siblings().removeClass("selVip");
        	
        	if($(this).attr("id")=="class1"){
        		$(".level1").show();
        		$(".level2").hide();
        		$(".class1").html("#(mediumName)");
        		$(".vipPrice").html("￥#(mediumRecommendRule.recAmount)元");
        		$(".vipMoney").attr('style','background:url(#(ctxWapSt)/h5css/images/middle.png) no-repeat;background-size:100% 100%;');
        		$(".member").attr('style','background:url(#(ctxWapSt)/h5css/images/Vbg.png) no-repeat;background-size:100% 100%;');
        		if(curlevel=='#(mediumRecommendRule.id)'){
        			$(".gopay").hide();
        			$(".nopay").show();
        		}else{
        			$(".gopay").attr('level','#(mediumRecommendRule.id)')
        			$(".gopay").show();
        			$(".nopay").hide();
        		}
        	}else{
        		$(".level2").show();
       			$(".level1").hide();
        		$(".class1").html("#(seniorName)");
        		$(".vipPrice").html("￥#(seniorRecommendRule.recAmount)元");
        		$(".vipMoney").attr('style','background:url(#(ctxWapSt)/h5css/images/high.png) no-repeat;background-size:100% 100%;');
        		$(".member").attr('style','background:url(#(ctxWapSt)/h5css/images/Vbg.png) no-repeat;background-size:100% 100%;');
        		if(curlevel=='#(seniorRecommendRule.id)'){
        			$(".gopay").hide();
        			$(".nopay").show();
        		}else{
        			$(".gopay").attr('level','#(seniorRecommendRule.id)')
        			$(".gopay").show();
        			$(".nopay").hide();
        		}
        	}
        })
    })
</script>
</html>